<?php
class AccountTokenSinglePeriodStat extends CFormModel {
	public $tokenYear;
	public $tokenMonth;
	public $projectId;
	public $showZeroCategory;

	public function rules() {
		return array(
			array(
				'tokenYear, tokenMonth',
				'required'
			),
			array(
				'showZeroCategory, projectId, tokenYear, tokenMonth',
				'numerical',
				'integerOnly' => true,
			),
		);
	}

	public function attributeLabels() {
		return array(
			'projectId' => '项目',
			'tokenYear' => '时间',
			'tokenMonth' => '月份',
			'showZeroCategory'=>'显示为零科目'
		);
	}

	/**
	 * @return CDbCriteria
	 */
	public function createCriteria() {
		$criteria = new CDbCriteria;

		$criteria->compare('tokenYear', $this->tokenYear);
		$criteria->compare('tokenMonth', $this->tokenMonth);
		if ($this->projectId) {
			$criteria->compare('projectId', $this->projectId);
		} else {
			$criteria->addInCondition('projectId', AccountTokenProject::getCompanyProjectIds());
		}
		return $criteria;
	}
}
